package com.nb.controller;

import com.nb.common.response.ResponseVO;
import com.nb.domain.User;
import com.nb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户控制器
 * Created by fly on 2017/11/12.
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据用户主键获取用户信息
     * @param userId
     * @return
     */
    @RequestMapping(path = "/findUserById", method = RequestMethod.POST)
    public String findUserById(int userId) {
        try {
            User userById = userService.findUserById(userId);
            System.out.println(userById.toString());
        } catch (Exception e) {
            e.printStackTrace();
            return "FAIL";
        }
        return "SUCCESS";
    }

    /**
     * 获取用户列表
     * @return
     */
    @RequestMapping(path = "/queryUserList", method = RequestMethod.POST)
    public ResponseVO<List<User>> queryUserList() {
        ResponseVO<List<User>> responseVO = new ResponseVO<>();
        try {
            List<User> userList = userService.queryUserList();
            responseVO.setResponseVO(200, "SUCCESS", userList);
        } catch (Exception e) {
            e.printStackTrace();
            responseVO.setResponseVO(500, "系统异常");
        }
        return responseVO;
    }
}
